package com.qiangqiang.resoldhouse.controller;

import com.qiangqiang.resoldhouse.entity.NewsSelect;
import com.qiangqiang.resoldhouse.entity.User;
import com.qiangqiang.resoldhouse.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

/**
 * Description: resoldhouse
 * Create by jeff on 2018-8-10 10:14
 */
@Controller
public class SystemController {
    @Autowired
    private NewsService newsService;
    //后台主页
    @RequestMapping("/sys_index")
    public String sysIndex(User user) {
        if ("admin".equals(user.getAccount()) && "123456".equals(user.getPassword())) {
            return "system/sys_index";
        }
        else {
            return "error_login";
        }
    }

    //后台登录
    @RequestMapping("/sys_login")
    public String sysLogin() {
        return "system/login_manager";
    }


    //后台简介
    @RequestMapping("/sys_introduce")
    public String sysIntroduce() {
        return "system/sys_introduce";
    }

    //后台添加经纪人
    @RequestMapping("/sys_insertagent")
    public String insertAgent() {
        return "system/sys_insertagent";
    }

    //后台添加新闻
    @RequestMapping("/sys_insertnews")
    public String insertNews() {
        return "system/sys_insertnews";
    }

    //后台图表页
    @RequestMapping("/sys_housecount")
    public String chart(){
        return "system/sys_housecount";
    }

    //前台首页
//    @RequestMapping("/index")
//    public String index() {return "index";}

    @RequestMapping(value={"/index","/"})
    public String index(@RequestParam(defaultValue = "1") Integer page, Map<String, Object> map, NewsSelect select) {
        if (select.getOrder() == null || select.getOrder().trim().equals("")) select.setOrder("default");
        if (select.getTitle() == null || select.getTitle().trim().equals("")) select.setTitle(null);
        map.put("pageDTO", newsService.findPage(page, select));
        map.put("select", select);
        return "index";
    }

    //登录页面
    @RequestMapping("/login_user")
    public String loginUser() {
        return "login_user";
    }

    //登录页面
    @RequestMapping("/login_agent")
    public String loginAgent() {
        return "login_agent";
    }

    @RequestMapping("logout")
    public String logout(HttpSession session){
        session.removeAttribute("agent");
        session.removeAttribute("user");
        return "redirect:/login_user";
    }

    //注册页面
    @RequestMapping("/signup")
    public String signup() {
        return "signup";
    }

    //新闻页面
    @RequestMapping("/news")
    public String news() {
        return "news";
    }

    @RequestMapping("/user_index")
    public String userIndex() {
        return "userPage/index";
    }

    @RequestMapping("/user_second")
    public String userSecond() {
        return "userPage/second";
    }

    @RequestMapping("/user_third")
    public String userThird() {
        return "userPage/third";
    }

    @RequestMapping("/user_fouth")
    public String userFouth() {
        return "userPage/fouth";
    }

    @RequestMapping("/user_fivth")
    public String userFivth() {
        return "userPage/fivth";
    }

    @RequestMapping("/user_sixth")
    public String userSixth() {
        return "userPage/sixth";
    }


}
